﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Data.Model;
using ZLCMS.Web.Temp;
using ZLCMS.Business.Util;
using NHibernate;
using DotNet.Common.NHibernateUtil;

namespace ZLCMS.Web.SystemManage.Template.Web
{
    public partial class ShowPageListDialog : System.Web.UI.Page
    {
        protected TemplatePageUtil _pageUtil;
        protected void Page_Load(object sender, EventArgs e)
        {
            string code = UserKit.GetUserAccountWithoutException();
            _pageUtil = new TemplatePageUtil(code);

            int tempId = TemplateUtil.GetUserTemplateId(code);
            using(ISession session = SessionFactoryHelper.CreateSession())
            {
                repeater1.DataSource = session.CreateQuery("from CmsUserTemplatePage where UserTempId=:tid order by PageLevel desc, Sort")
                    .SetParameter("tid", tempId)
                    .List<ZLCMS.Data.Model.CmsUserTemplatePage>();
            }
            repeater1.DataBind();
        }

        public string GetPageUrl(object item)
        {
            string result = "";
            CmsUserTemplatePage page = item as CmsUserTemplatePage;
            if (page.PageLevel == "1")
            {
                result = _pageUtil.GetHomePage();
            }
            else
            {
                result = _pageUtil.GetPage(page.Id);
            }
            return ServerUtil.GetRootURI() + result;
        }
    }
}